<template>
  <van-popup :close-on-click-overlay="false" v-model="ResShow" @close="close" round :style="{ background: 'transparent' }">
    <div class="box">
      <div class="box_top">
        <div class="answer_popup_title">参与答题</div>
        <div class="answer_popup_title">获取{{integral}}奖励</div>
        <img :src="imgHost" alt="" class="pos" />
      </div>
      <div class="box_bottom">
        <div class="box_bottom_conten">
          <div class="box_bottom_conten_text flex flex-a-c">
            <div class="iconStatusBox flex flex-a-c flex-j-c">
              <i class="iconfont icon-info-tick" v-if="resType.answer_res"></i>
              <i class="iconfont icon-icon_close" v-else></i>
            </div>
            <span>{{ resType.answer_res ? "恭喜答对" : "很遗憾！再接再励" }}</span>
          </div>
          <div class="box_bottom_conten_minText" v-if="resType.answer_res">获得{{resType.reward}}{{integral}}</div>
          <div class="box_bottom_conten_minText" v-else>赠送您{{resType.reward}}{{integral}}作为答题奖励</div>
        </div>
        <div class="tips">{{ count }}s后自动关闭弹窗</div>
      </div>
    </div>
    <div class="iconBox">
      <i class="iconfont icon-adsystem_icon_cancle" @click="close"></i>
    </div>
  </van-popup>
</template>
<script>
export default {
  props: {
    ResShow: {
      type: Boolean,
      default: false
    },
    resType: {
      type: Object,
      default: {}
    }
  },
  data() {
    return {
      count: 5,
      interFun: null,
      imgHost: `${window.location.origin}/static/local/live-broadcast-question/question.png`,
      integral: window.localStorage.integral,
    };
  },
  mounted() {},
  watch: {
    ResShow(val, oval) {
      if (val) {
        this.count = 5;
        this.interFun = setInterval(() => {
          this.count -= 1;
          if (this.count <= 0) {
            this.interFun && this.clearInterval_fun();
            this.close();
            return;
          }
        }, 1000);
      } else {
        this.count = 5;
        this.clearInterval_fun();
      }
    }
  },
  beforeDestroy() {
    this.clearInterval();
    this.init();
  },
  methods: {
    init() {
      this.count = 5;
      this.interFun = null;
    },
    close() {
      this.$emit("update:ResShow", false);
    },
    clearInterval_fun() {
      if (this.interFun) {
        clearInterval(this.interFun);
        this.interFun = null;
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.iconBox {
  margin: 0 auto;
  margin-top: 1.56rem;
  .icon-adsystem_icon_cancle {
    font-size: 2rem;
    color: #ffffff;
  }
}
.box {
  background: #f15353;
  width: 18.75rem;
  border-radius: 0.75rem;
  margin: 0 auto;
  .box_top {
    padding: 0.78rem 0.94rem;
    box-sizing: border-box;
    text-align: left;
    position: relative;
    .answer_popup_title {
      font-weight: bold;
      font-size: 1.13rem;
      color: #ffffff;
    }
    .pos {
      position: absolute;
      right: 0.5rem;
      bottom: -0.5rem;
      width: 4.34rem;
      height: 4.22rem;
    }
  }
  .box_bottom {
    position: relative;
    width: 18.75rem;
    background: #fff;
    border-radius: 0.75rem;
    padding: 0.94rem;
    box-sizing: border-box;
    .tips {
      font-weight: 400;
      font-size: 0.88rem;
      color: #6e6e79;
      text-align: center;
      margin-top: 1.03rem;
      line-height: 1rem;
    }
    .box_bottom_conten {
      padding: 0.94rem;
      box-sizing: border-box;
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: column;
      background: #ffefe6;

      .box_bottom_conten_text {
        font-weight: bold;
        font-size: 1.25rem;
        color: #72280c;
        .iconStatusBox {
          margin-right: 0.38rem;
          width: 1.25rem;
          height: 1.25rem;
          border-radius: 50%;
          background: #33a512;
          .iconfont {
            color: #fff;
            font-size: 0.88rem;
          }
        }
      }
      .box_bottom_conten_minText {
        font-weight: 500;
        font-size: 0.94rem;
        color: #72280c;
        line-height: 1rem;
        margin-top: 0.9rem;
      }
    }
  }
}
</style>
